/**
 * @summary 关注请求模块
 */
import req from '@/utils/request';
import * as URL from '@/constants/api';

export function follow(id) {
  return req({
    url: URL.FOLLOW,
    method: 'post',
    data: {
      target: id,
    }
  })
    // 处理成功
    .then(res => res.data.message)
    // 处理失败
    .catch(err => Promise.reject(err.response.data.message))
}

/**
  *@param { object } params mobile & code
 * @summary 登录
 */
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params
  })
    // 处理成功
    .then(res => {
      localStorage.setItem('TOKEN', `Bearer ${ res.data.data.token}`);
      return res.data.message
    })
    // 处理失败
    .catch(err => Promise.reject(err.response.data.message))
}
/**
 * @summary 用户信息
 */
export function getUserInfo() {
  return req({
    url: URL.USER_INFO,
  })
    // 处理成功
    .then(res => res.data.data)
    // 处理失败
    .catch(() =>({}))
}
